﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WPF基础.控件
{
    /// <summary>
    /// A20_TreeView.xaml 的交互逻辑
    /// </summary>
    public partial class A20_TreeView : Window
    {
        public A20_TreeView()
        {
            InitializeComponent();

            List<Family> family = new List<Family>();

            Family Parents = new Family() { Name = "Parents" };
            Family Parents_1 = new Family() { Name = "Parents_1" };

            Parents.Members.Add(new FamilyMember() { Name = "Son #1.1" });
            Parents.Members.Add(new FamilyMember() { Name = "Son #1.2" });
            Parents.Members.Add(new FamilyMember() { Name = "Son #1.3" });
            Parents_1.Members.Add(new FamilyMember() { Name = "Daughter #2.1" });
            Parents_1.Members.Add(new FamilyMember() { Name = "Daughter #2.2" });

            TreeView_1.Items.Add(Parents);
            TreeView_1.Items.Add(Parents_1);


            //使用MenuItem
            MenuItem Root = new MenuItem() { Title = "根节点" };
            MenuItem Children_1 = new MenuItem() { Title = "子节点1" };
            MenuItem Children_2 = new MenuItem() { Title = "子节点2" };

            Children_1.Items.Add(new MenuItem() { Title = "子节点1.1" });
            Children_1.Items.Add(new MenuItem() { Title = "子节点1.2" });
            Children_1.Items.Add(new MenuItem() { Title = "子节点1.3" });
            Children_2.Items.Add(new MenuItem() { Title = "子节点2.1" });
            Children_2.Items.Add(new MenuItem() { Title = "子节点2.2" });

            Root.Items.Add(Children_1);
            Root.Items.Add(Children_2);

            TreeView_2.Items.Add(Root);

        }


    }

    public class Family
    {
       public Family()
        {
            this.Members = new ObservableCollection<FamilyMember>();
        }
        public string Name { get; set; }
        public ObservableCollection<FamilyMember>Members { get; set; }

       

    }
    public class FamilyMember
    {
        public string Name { get; set; }
        public string Age { get; set; }
    }

    public class MenuItem
    {
        public MenuItem()
        {
            this.Items = new ObservableCollection<MenuItem>();
        }

        public string Title { get; set; }

        public ObservableCollection<MenuItem> Items { get; set; }
    }






}
